import { Controller, Get, Post, UseInterceptors, UploadedFile,Res } from '@nestjs/common';
import { UploadService } from './upload.service';
import type { Response } from 'express'
import { zip } from 'compressing'
import { join } from 'path'
import { FileInterceptor,FilesInterceptor } from '@nestjs/platform-express'
// import { CreateUploadDto } from './dto/create-upload.dto';
// import { UpdateUploadDto } from './dto/update-upload.dto';
@Controller('upload')
export class UploadController {
  constructor(private readonly uploadService: UploadService) {}
  @Post('album')
  @UseInterceptors(FileInterceptor('file'))
  upload(@UploadedFile() file){
    return '你好'
  }
  
  @Get('export')
  downLoad(@Res() res:Response){
    const url = join(__dirname, '../images/1678519836696.jpg');
    res.download(url)
  }
  
  @Get('stream')  //文件流，第十四章
  async down (@Res() res:Response){
     const url = join(__dirname, '../images/1678519836696.jpg');
     const tarStream = new zip.Stream()
     await tarStream.addEntry(url)
     
     res.setHeader('Content-Type','application/ontet-stream');
     res.setHeader(
         'Content-Dispostion',
         'attachment;filename=newking'
     )
     tarStream.pipe(res)
     
  }
 
}
